import request from "../request.ts"

export const getAllTagApi = () => {
  return request({
    url: "/api/tag",
    method: "GET"
  })
}

/**
 *
 * @param id 图片ID
 * @returns 标签数组
 */
export const getImageTagsApi = (id: string) => {
  return request({
    url: "/api/image-tag/" + id,
    method: "GET"
  })
}

/**
 *
 * @param id 数据集ID
 * @returns 标签数组
 */
export const getCategoryTagsApi = (id: string) => {
  return request({
    url: "/api/category-tag/" + id,
    method: "GET"
  })
}

//管理员

/**
 *
 * @param id 新标签ID
 * @param name 新标签显示名
 * @returns
 */
export const createTagApi = (name: string) => {
  return request({
    url: "/admin/api/tag",
    method: "PUT",
    params: {
      name
    }
  })
}

/**
 *
 * @param id 标签ID
 * @param newName 新名称
 * @returns
 */
export const updateTagApi = (id: number, newName: string) => {
  return request({
    url: "/admin/api/tag",
    method: "POST",
    params: {
      id,
      newName
    }
  })
}

/**
 *
 * @param id 删除标签ID
 * @returns
 */
export const deleteTagApi = (id: number[]) => {
  return request({
    url: "/admin/api/tag",
    method: "DELETE",
    data: id
  })
}

/**
 *
 * @param imageId 图片ID
 * @param tagsId 标签ID
 * @returns
 */
export const addTagToImageApi = (imageId: string, tagsId: number[]) => {
  return request({
    url: "/admin/api/image-tag",
    method: "POST",
    data: {
      imageId,
      tagsId
    }
  })
}

/**
 *
 * @param imageId 图片ID
 * @param tagsId 标签ID
 * @returns
 */
export const deleteTagFromImageApi = (imageId: string, tagsId: number[]) => {
  return request({
    url: "/admin/api/image-tag",
    method: "DELETE",
    data: {
      imageId,
      tagsId
    }
  })
}

/**
 *
 * @param categoryId 数据集ID
 * @param tagsId 标签ID
 * @returns
 */
export const addTagToCategoryApi = (categoryId: number, tagsId: number[]) => {
  return request({
    url: "/admin/api/category-tag",
    method: "POST",
    data: {
      categoryId,
      tagsId
    }
  })
}

/**
 *
 * @param categoryId 数据集ID
 * @param tagsId 标签ID
 * @returns
 */
export const deleteTagFromCategoryApi = (categoryId: number, tagsId: number[]) => {
  return request({
    url: "/admin/api/category-tag",
    method: "DELETE",
    data: {
      categoryId,
      tagsId
    }
  })
}
